<style type="text/css">
<!--
    #Content {
        width: 100% !important; 
    }
    div.divRight {
        float: right;
        width: 99.7%;
        border: 1px solid #ED7600;
    }
    

    h3.title {
	    color: #0A4874;
        font-weight: bold;
        border-bottom: 1px dashed #D5D5D5;
        padding-bottom: 10px;
        padding-left: 10px;
	}

    div.info_game{
        color: black;
    }
    div.info_game > table {
        width: 100%;
    }
   
    table.coin_exchange {
        width: 80%;
        border: 1px solid #a5b4b7;
        font-weight: normal !important;
    }
    table.coin_exchange th{
        background-color: #a5b4b7;
        padding: 5px;
        color: white;
    }
    table.coin_exchange td{
        
        padding: 5px;
        
    }
    /*so chan */
    table.coin_exchange tr.even
    {
        
    }
    /*so le*/
    table.coin_exchange tr.odd{   
        background-color: #84E4EA;
    }
    
-->
</style>

<script type="text/javascript">
<!--
    <?php if(isset($game_id)):?>
    var _coin_exchange = JSON.parse('<?=mysql_real_escape_string(json_encode($coin_exchange))?>');
	function coinToPoint(coin)
    {
        var point = coin;
        var index = -1;
        for(var i =0 ;i< _coin_exchange.length; i++)
        {
            if (Number(_coin_exchange[i].coin) > Number(coin))
            {
                index = i-1;
                break;
            }
            else if (Number(_coin_exchange[i].coin) == Number(coin))
            {
                index = i;
                break;
            }
            else if (_coin_exchange.length == i+1 && Number(coin) > Number(_coin_exchange[i].coin))
            {
                index = i;
                break;
            }
        } 
        if (index == -1)
        {
            //get value index 0
            if (_coin_exchange.length == 0)
            {
                //no exchange
                point = coin; 
            }
            else
            {
                //exchange
                var point_sys = _coin_exchange[0].point;
                var coin_sys = _coin_exchange[0].coin;
                point = coin * point_sys / coin_sys;
            }
        }
        else 
        {
            //get value last
            var point_sys = _coin_exchange[index].point;
            var coin_sys = _coin_exchange[index].coin;
            point = coin * point_sys / coin_sys;
        }
        
        $('#msg_coin').html("You will be add <b style='color:red;'>" + parseInt(point) + "</b> points on your account.");
    }
    <?php endif;?>
	function chooseGame(obj)
    {
        window.location = '/pay/coinExchange/' + obj.value;
    }
-->
</script>
<style type="text/css">
<!--
	div.select_games {
	    color: #0A4874;
        font-weight: bold;
	    padding: 10px;
        border-bottom: 1px dashed #D5D5D5;
	}
-->
</style>
<div class="divRight">
    <?=$menu?>
    <h3 class="title">.::. Withdraw Points From Game</h3>
    <?=$showInfoPlayer?>
    <!-- COIN EXCHANGE -->
    <div class="select_games">
        <span>Choose games: </span>
        <select onchange="chooseGame(this)">
        <?php foreach($games_detail as $games){  ?>
            <?php if (isset($game_id) && $game_id == $games['id']): ?>
                <option value="<?=$games['id']?>" selected="true" ><?=$games['name']?></option>
            <?php else:?>
                <option value="<?=$games['id']?>"><?=$games['name']?></option>
            <?php endif; ?>
        <?php } ?>
        </select>
    </div>
    <?php if (isset($game_id)) :?>
    <style type="text/css">
<!--
	div.info_game {
	   padding: 10px;
	}
    div.info_game > h2{
        padding-bottom: 10px;
    }
    div.info_game > table td.img{
        vertical-align: top;
        text-align: center;
        width: 30%;
        padding: 5px;
    }
    div.info_game > table td{
        vertical-align: top;
        padding: 5px;
    }
    div.info_game > table table{
        color: #0A4874;
        font-weight: bold;
    }
    div.info_game span.blue {
        color: #0A4874;
        font-weight: bold;
    }
-->
</style>
    <div class="info_game">
        <h2> Get points from the game <?=$game_detail->name?></h2>
        <table>
            <?php if( isset($GetResult) && $GetResult == false): ?>
                <tr>
                    <td colspan="2">
                        <div class="error"> 
                            <span><?=$GetMessage?></span>
                        </div>
                    </td>
                </tr>    
                <?php elseif (isset($GetResult) && $GetResult == true):?>
                <tr>
                    <td colspan="2">
                        <div class="success"> 
                            <span><?=$GetMessage?></span>
                        </div>
                    </td>
                </tr>
                <?php endif; ?>
            <tr>
                <td class="img" ><img style="width: 100%;" src="/<?=GAME_IMAGES_URI. $game_detail->image?>" /></td>
                <td>
                    <table>
                    <tr>
                        <td>Player name:</td>
                        <td><span style="color: black;font-weight:normal;"><?=$game_player->player_username?> </span></td>
                    </tr>
                    <tr>
                        <td>Current balance:</td>
                        <td><span style="color: red;"><?=$game_player->coin_balance?></span> <span style="color: black;font-weight:normal;">points</span> </td>
                    </tr>    
                    <tr>
                        <td>Deposit points:</td>
                        <td>
                            <form method="post" action="/game/get_points/<?=$game_id?>">
                                <input type="text" oninput="coinToPoint(this.value)" value="0" name="coin"/>
                                <input type="hidden" value="<?=$game_detail->game_brand_param?>" name="game_brand_param"/>
                                <input type="hidden" value="/pay/coinExchange/<?=$game_id?>" name="url_back"/>
                                <input type="submit" value="Accept" name="get_points" class="button"/>
                            </form>
                        </td>
                    </tr> 
                    <tr>
                        <td></td>
                        <td><div id="msg_coin">You will be add <b style="color:red;">0</b> points on your account.</div></td>
                    </tr>                   
                    </table>
                    <!--
                    <?php if (isset($coin_exchange) && count($coin_exchange) > 0) : ?>
                    <p>
                        <span class="blue">Coins exchange:</span>
                    </p>
                    <table class="coin_exchange">
                        <thead>
                            <tr>
                                <th style="width: 20%;"> No.</th>
                                <th>Exchange</th>
                            </tr>
                        </thead>
                              <?php
                                $i= 0;
                                foreach($coin_exchange as $coin){
                                ?>
                                    <tr class="<?=($i%2 ==0)?'even':'odd'?>" >
                                        <td><?=++$i?></td>
                                        <td><?=(int)$coin->coin?> (Coins) -&gt; <?=(int)$coin->point?> (Points)</td>
                                    </tr>
                                <?php
                                }
                              ?>
                            </table>
                    <?php endif;?>
                    -->
                </td>
            </tr>
        </table>
        
    </div>
    <?php endif; ?>

    <!-- END POINT EXCHANGE -->
</div>


